package com.ws.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ws.bean.Customer;
import com.ws.bean.RenralOrder;
import com.ws.bean.Staff;
import com.ws.bean.Vehicle;
import com.ws.bean.VehicleCount;
import com.ws.bean.VehicoleBrand;
import com.ws.common.CommonResult;
import com.ws.service.RenralOrderService;
import com.ws.util.Page;

@RestController
@RequestMapping("order")
public class RenralOrderController {
	@Autowired
	RenralOrderService service;
	@GetMapping("select")
	public CommonResult getOrders(Customer customer,Page page) {
		List<RenralOrder> list = service.getOrders(customer,page);
		int count = service.getCount(customer);
		Map map = new HashMap<>();
		map.put("list", list);
		map.put("count", count);
		return CommonResult.success(map);
		}
	@PostMapping("add")
	public CommonResult addOrder(@RequestBody RenralOrder order) {
		int result = service.addOrder(order);
		return CommonResult.success();
		}
	@DeleteMapping("del/{id}")
	public CommonResult delOrder(@PathVariable Integer id) {
		int result = service.delOrder(id);
		return CommonResult.success();
	}
	@PutMapping("edit")
	public CommonResult editOrder(RenralOrder order) {
		int result = service.editOrder(order);
		return CommonResult.success();
	}
	@GetMapping("getcustomer")
	public CommonResult getCustomers() {
		List<Customer> list = service.getCustomers();
		return CommonResult.success(list);
	}
	@GetMapping("getbrands")
	public CommonResult getBrands() {
		List<VehicoleBrand> list = service.getBrands();
		return CommonResult.success(list);
	}
	@GetMapping("getmodelbyid/{id}")
	public CommonResult getModelByID(@PathVariable Integer id) {
		List<Vehicle> list = service.getModelByID(id);
		System.out.println("hhh");
		System.out.println(list);
		return CommonResult.success(list);
	}
	@GetMapping("getPlateNum/{model}")
	public CommonResult getPlateNum(@PathVariable String model) {
		System.out.println("ss");
		List<Vehicle> list = service.getPlateNum(model);
		System.out.println("hhh");
		System.out.println(list);
		return CommonResult.success(list);
	}
	@GetMapping("check")
	public CommonResult checkOrder(RenralOrder order) {
		int result = service.checkOrder(order);
		if(result > 0) return CommonResult.success();
		else {
		return CommonResult.fail(100,"检查和维修还未完成");
		}
	}
	@PutMapping("jiajia")
	public CommonResult vehicleJia(RenralOrder order) {
		int result = service.vehicleJia(order);
		return CommonResult.success();
	}
	@GetMapping("getcount")
	public CommonResult getVehicleCount() {
		List<VehicleCount> list = service.getVehicleCount();
		return CommonResult.success(list);
	}
	@GetMapping("getname")
	public CommonResult getVehicleName() {
		List<String> list = service.getVehicleName();
		return CommonResult.success(list);
	}
	@GetMapping("getstaff")
	public CommonResult getStaff() {
		List<Staff> list = service.getStaff();
		return CommonResult.success(list);
	}
}
